< previous page page_95 next page >

Page 95
Text Box Events
Youll probably write a lot of code for text boxes because these are the controls users interact with most often. A lot of the events you will write with text boxes employ data validation, or keeping track of data that has changed. Lets look at some of the more common ones.
The TextBox_Change( ) Event
The Change() event is fired when the user types something in the text box. You might write code in this event to enable the Save button because this event signifies that the data has changed on the form.
EXERCISE
Adding Events to Text Boxes
1. Open the frmEmployee form.
2. Double-click the txtFirst text box and add the following code:
Private Sub txtFirst_Change()
cmdSave.Enabled = True
End Sub
analysis.gifThe Change() event is typically used to determine whether the data in a text box has changed.

This code changes the cmdSave.Enabled property to True whenever the user changes the text in the txtFirst text box. Of course, youll need to add this code to every Change() event for every text box on the form.
EXERCISE
Add More Change( ) Event Code
1. Add the same code to every Change() event for every text box.
2. Run the project and type some data into one of the text boxes. You should see the Save button become enabled with the first key you press.
analysis.gifYou should write a Change() event for every text box to determine whether any data changes on any text box.

 
< previous page page_95 next page >

If you like this book, buy it!